#pragma once
#include <map>
#include <string>

class VarBase
{
public:
	VarBase()
	{
		_name = "unnamed";

		_ChangeCallback = NULL;
	};

	VarBase(const std::string& name)
	{
		_name = name;

		_ChangeCallback = NULL;
	};

	~VarBase()
	{
		_ChangeCallback = NULL;
	}

	const std::string& getName()
	{
		return _name;
	};

	int _type;
	std::string _strval;
	std::string _name;

	virtual void setChangeCallback(void (*_OnChange)())
	{
		_ChangeCallback = _OnChange;
	};

	void (*_ChangeCallback)();
};

class IntVar : public VarBase
{
public:
	IntVar(const std::string& name, int val, int min, int max);
	~IntVar();

	void setValue(int v);
	int  getValue();
private:
	int _val;
	int _min;
	int _max;
	int _default;
};

class BoolVar : public VarBase
{
public:
	BoolVar(const std::string& name, bool dft);
	~BoolVar();

	void setValue(bool v);
	bool getValue();
private:
	bool _val;
	bool _default;
};

class FloatVar : public VarBase
{
public:
	FloatVar(const std::string& name, float dft, float min, float max);
	~FloatVar();

	void setValue(float v);
	float getValue();
private:
	float _val;
	float _default;
	float _min;
	float _max;
};

class StringVar : public VarBase
{
public:
	StringVar(const std::string& name, const std::string& dft);
	~StringVar();

	void setValue(const std::string& v);
	const std::string& getValue();
private:
	std::string _default;
};

class VarManager
{
public:
	VarManager(const std::string& workDir);
	~VarManager();

	VarBase* Get(const std::string& name);
private:
	void Register(VarBase* var);
	std::map<std::string, VarBase*> m_vars;
	std::string m_workDir;
};